import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import 'package:provider/provider.dart';
import 'package:star_unbounded/model/clipboard_data.dart';
import 'package:star_unbounded/model/global_theme.dart';
import 'package:star_unbounded/pages/index/widget/bottom_bar.dart';

import "package:star_unbounded/utils/clipboard.dart";

class IndexPage extends StatefulWidget {
  const IndexPage({super.key, required this.title});


  final String title;

  @override
  State<IndexPage> createState() => _IndexPageState();
}

class _IndexPageState extends State<IndexPage> {



  Future<void> read() async {
    String? text =  await Clipboard.read();
    if (kDebugMode) {
      print(text);
    }
  }

  Future<void> readImage() async {
    Clipboard.readImage();
  }
  void handleSetLight(BuildContext context){
    context.read<GlobalTheme>().handleBrightness();
  }

  void onSlectedColor(int index){
    context.read<GlobalTheme>().handleColorSchemeSeed(index);
  }

  void onPast(BuildContext context){
    context.read<ClipboardData>().onShow();

  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title,style: Theme.of(context).textTheme.titleMedium,),
        actions: [
          TextButton(
            onPressed: () {
              Navigator.pushNamed(context, "/login",arguments: "1");
            },
            child: const Text("登录"),
          ),
          Builder(builder: (context){
            bool useLightTheme = context.select((GlobalTheme g)=>g.useLightTheme);
            return IconButton(onPressed: ()=>handleSetLight(context), icon: useLightTheme? const Icon(Icons.light_mode) : const Icon(Icons.dark_mode));
          }),
          Builder(builder: (context){
            EnumColorSeed selectColor = context.select((GlobalTheme g)=>g.colorSchemeSeed);
            return PopupMenuButton(
              icon: const Icon(Icons.color_lens_outlined),

              itemBuilder: (context){
                return List.generate(EnumColorSeed.values.length, (index){
                  EnumColorSeed currentColor = EnumColorSeed.values[index];
                  return PopupMenuItem(
                    value: index,
                    enabled: currentColor.color != selectColor.color,
                    child: Wrap(
                      children:  [
                        Padding(padding: const EdgeInsets.only(left: 10),child: Icon(
                          Icons.color_lens_outlined,
                          color: currentColor.color,
                        ),),
                        Padding(padding:const EdgeInsets.only(left: 20),child: Text(currentColor.name),)
                      ],
                    ),

                  );
                });
              },
              onSelected: onSlectedColor,
            );

          })
        ],
      ),
      body: const SafeArea(
        bottom: false,
        child:  Column(
          mainAxisAlignment: MainAxisAlignment.center,
          mainAxisSize: MainAxisSize.min,
          children: <Widget>  [
              Expanded(child: Align(

              )),
              BottomBar(),
          ],
        ),
      ),


    );
  }
}